//
//  MYGHealthManagementFoodCell.swift
//  MYGrow
//
//  Created by 林矗 on 2024/3/9.
//

import UIKit

class MYGHealthManagementFoodCell: MYGHealthManagementBaseCell {
    // MARK: - Property
    
    override var model: MYGHealthManagementRowModel? {
        didSet {
            guard let model = (model as? MYGHealthManagementFoodModel) else { return }
            todayContentLabel.text = model.todayIn
            compareContentLabel.text = model.lastDayCompary
            carbonView.content = model.carbon
            fatView.content = model.fat
            proteinView.content = model.protein
        }
    }
    

    // MARK: - init
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        selectionStyle = .none
        contentView.backgroundColor = .white
        configUI()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    // MARK: - UI
    private func configUI() {
        contentView.addSubviews([
            bgImageView
        ])
        
        bgImageView.addSubviews([
            iconImageView,
            titleLabel,
            todayTitleLabel,
            todayContentLabel,
            compareTitleLabel,
            compareContentLabel,
            carbonView,
            fatView,
            proteinView
        ])
        
        bgImageView.snp.makeConstraints { make in
            make.top.equalTo(15)
            make.left.right.equalToSuperview().inset(22.5)
            make.height.equalTo(160.5)
            make.bottom.equalToSuperview()
        }
        
        iconImageView.snp.makeConstraints { make in
            make.top.equalTo(16.5)
            make.left.equalTo(13.5)
            make.size.equalTo(CGSize(width: 22, height: 22))
        }
        
        titleLabel.snp.makeConstraints { make in
            make.left.equalTo(iconImageView.snp.right).offset(4.5)
            make.centerY.equalTo(iconImageView)
            make.height.equalTo(21)
        }
        
        todayContentLabel.snp.makeConstraints { make in
            make.top.equalTo(iconImageView.snp.bottom).offset(10)
            make.left.equalTo(13.5)
            make.height.equalTo(22.5)
            make.width.equalTo(95)
        }
        
        todayTitleLabel.snp.makeConstraints { make in
            make.top.equalTo(todayContentLabel.snp.bottom).offset(5.5)
            make.left.equalTo(13.5)
            make.height.equalTo(16.5)
            make.width.equalTo(95)
        }
        
        compareContentLabel.snp.makeConstraints { make in
            make.centerY.equalTo(todayContentLabel)
            make.left.equalTo(todayContentLabel.snp.right).offset(40)
            make.height.equalTo(22.5)
            make.width.equalTo(95)
        }
        
        compareTitleLabel.snp.makeConstraints { make in
            make.centerY.equalTo(todayTitleLabel)
            make.left.equalTo(todayTitleLabel.snp.right).offset(40)
            make.height.equalTo(16.5)
            make.width.equalTo(95)
        }
            
        carbonView.snp.makeConstraints { make in
            make.left.equalTo(0)
            make.top.equalTo(todayTitleLabel.snp.bottom).offset(15)
            make.bottom.equalTo(-8)
        }
        
        fatView.snp.makeConstraints { make in
            make.left.equalTo(carbonView.snp.right)
            make.top.equalTo(todayTitleLabel.snp.bottom).offset(15)
            make.bottom.equalTo(-8)
            make.width.equalTo(carbonView)
        }
        
        proteinView.snp.makeConstraints { make in
            make.left.equalTo(fatView.snp.right)
            make.top.equalTo(todayTitleLabel.snp.bottom).offset(15)
            make.bottom.equalTo(-8)
            make.width.equalTo(carbonView)
            make.right.equalTo(0)
        }
        
    }
    
    // MARK: - lazy load
    private lazy var bgImageView: UIImageView = {
        let imageV = UIImageView(image: UIImage(named: "food_bg"))
        imageV.contentMode = .scaleAspectFill
        imageV.clipsToBounds = true
        imageV.isUserInteractionEnabled = true
        return imageV
    }()
    
    private lazy var iconImageView: UIImageView = {
        let imageV = UIImageView(image: UIImage(named: "food_icon"))
        imageV.contentMode = .scaleAspectFill
        imageV.clipsToBounds = true
        return imageV
    }()
    
    private lazy var titleLabel: UILabel = {
        let label = UILabel()
        label.font = .regular(15)
        label.text = "饮食"
        label.textColor = .rgba(255, 87, 143)
        return label
    }()
    
    private lazy var todayContentLabel: UILabel = {
        let label = UILabel()
        label.font = .medium(16)
        label.textColor = .black
        return label
    }()
    
    private lazy var todayTitleLabel: UILabel = {
        let label = UILabel()
        label.font = .regular(12)
        label.textColor = .rgba(139, 139, 139)
        label.text = "今日摄入"
        return label
    }()
    
    private lazy var compareContentLabel: UILabel = {
        let label = UILabel()
        label.font = .regular(11)
        label.textColor = .rgba(255, 87, 143)
        return label
    }()
    
    private lazy var compareTitleLabel: UILabel = {
        let label = UILabel()
        label.font = .regular(12)
        label.textColor = .rgba(139, 139, 139)
        label.text = "对比昨天"
        return label
    }()
    
    private lazy var carbonView: MYGHealthManagementTitleValueView = {
        let view = MYGHealthManagementTitleValueView(frame: .zero)
        view.title = "碳水"
        return view
    }()
    
    private lazy var fatView: MYGHealthManagementTitleValueView = {
        let view = MYGHealthManagementTitleValueView(frame: .zero)
        view.title = "脂肪"
        return view
    }()
    
    private lazy var proteinView: MYGHealthManagementTitleValueView = {
        let view = MYGHealthManagementTitleValueView(frame: .zero)
        view.title = "蛋白质"
        return view
    }()
}



